/*
 * WeatherResource.cpp
 *
 *  Created on: 2013. 11. 29.
 *      Author: mega
 */

#include "WeatherResource.h"
#include <Database/Static.h>

#include "../macro.h"

namespace ProjectZ { namespace NResource {

WeatherResource::WeatherResource()
{
	_weather = 49;	// 기본값 (맑음)
}

WeatherResource::~WeatherResource()
{

}

bool
WeatherResource::LoadResource()
{
	::Database::Command::Auto clsAuto(::Database::GETCOMMANDPOOL());
	clsAuto->SetQueryType(::Database::Command::SELECT);
	clsAuto->MakeQuery("SELECT NATIONAL_CODE, WEATHER_TYPE FROM resource_weather WHERE IS_ACTIVE=1");

	if (false == ::Database::GETSESSION()->SyncExecute(1, clsAuto))
		return false;

	if( clsAuto->GetErrorIdx() != 0 )
		return false;

	if (0 == clsAuto->ResultRowCount())
		return false;

	while (clsAuto->Next())
	{
		::Toolkit::Str<3> NATIONAL_CODE;
		clsAuto->GetRecord() >> NATIONAL_CODE >> _weather;

		if (0 != Config::Instance().GetResourceDatabase()._strNational.compare(NATIONAL_CODE.c_str()))
		{
			DEBUGLOG("%s:%d NATIONAL_CODE ERROR!!! Config National Code [%s] , Resource National Code [%s]",
					__FILE__, __LINE__,
					Config::Instance().GetResourceDatabase()._strNational.c_str(),
					NATIONAL_CODE.c_str());
			return false;
		}
	}

	return true;
}

int
WeatherResource::GetWeather()
{
	return _weather;
}

} /*NResource*/ } /*ProjectZ*/

